package com.example.graduation.controller;


import com.example.graduation.entity.Evaluate;
import com.example.graduation.form.IdForm;
import com.example.graduation.form.PinglunForm;
import com.example.graduation.service.impl.EvaluateServiceImpl;
import com.example.graduation.util.R;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author xyc
 * @since 2022-02-11
 */
@RestController
@RequestMapping("/evaluate")
public class EvaluateController {

    @Resource
    private EvaluateServiceImpl evaluateService;


    /**
     * @api {POST} /evaluate/pinglun 评论
     * @apiVersion 1.0.0
     * @apiGroup EvaluateController
     * @apiName pinglun
     * @apiParam (请求参数) {String} token
     * @apiParamExample 请求参数示例
     * token=H1as2b
     * @apiParam (请求体) {Number} orderid
     * @apiParam (请求体) {String} photo
     * @apiParam (请求体) {String} content
     * @apiParamExample 请求体示例
     * {"orderid":1108,"photo":"4LaLA9SXj2","content":"gxvQwhUrjL"}
     * @apiSuccess (响应结果) {Object} response
     * @apiSuccessExample 响应结果示例
     * {}
     */
    @PostMapping("pinglun")
    @ResponseBody
    public R pinglun(@RequestHeader String token, @RequestBody PinglunForm form) {
        Evaluate pinglun = evaluateService.pinglun(token, form.getOrderid(), form.getPhoto(), form.getContent1());
        return R.ok().put("pinglun", pinglun);
    }


    /**
     * @api {POST} /evaluate/findShopEvaluate 查找商家评论列表
     * @apiVersion 1.0.0
     * @apiGroup EvaluateController
     * @apiName findShopEvaluate
     * @apiParam (请求体) {Number} shopId
     * @apiParamExample 请求体示例
     * {"shopId":6011}
     * @apiSuccess (响应结果) {Object} response
     * @apiSuccessExample 响应结果示例
     * {}
     */
    @PostMapping("findShopEvaluate")
    @ResponseBody
    public R findShopEvaluate(@RequestBody IdForm form) {
        List<Evaluate> shopEvaluate = evaluateService.findShopEvaluate(form.getShopId());
        return R.ok().put("shopEvaluate", shopEvaluate);
    }
}

